package com.bbs.action;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.bbs.dao.SectionDao;
import com.bbs.dao.impl.SectionDaoImpl;
import com.bbs.model.Section;

public class SectionAction extends BaseAction{
	
	private static final long serialVersionUID = 1L;
	private Section section;
	private SectionDao sectionDao;
	private List<Section> sectionList;
	/**
	 * 添加版块
	 * @return
	 * @throws IOException
	 */
	public String addSection() throws IOException{
		sectionDao=new SectionDaoImpl();
		//设置时间格式
		section.setSection_setup_time
			(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		sectionDao.save(section);
		return "addSection";
	}
	
	/**
	 * 修改
	 * @return
	 * @throws IOException
	 */
	public String updateSection() throws IOException{
		
		sectionDao=new SectionDaoImpl();
		sectionDao.update(section);
		return "addTopic";
	}
	/**
	 * 删除版块
	 * @return
	 * @throws IOException
	 */
	public String deleteSection() throws IOException{
		sectionDao=new SectionDaoImpl();
		sectionDao.delete(section.getSection_id());
		return " deleteSection";
	}
	/**
	 * 展示所有版块
	 * @return
	 * @throws IOException
	 */
	public String  listSection() throws IOException{		
		sectionDao=new SectionDaoImpl();
		sectionList=sectionDao.findAll();
		return "listSection";
	}

	
	public Section getSection() {
		return section;
	}


	public void setSection(Section section) {
		this.section = section;
	}

	public List<Section> getSectionList() {
		return sectionList;
	}


	public void setSectionList(List<Section> sectionList) {
		this.sectionList = sectionList;
	}
}
